#include "UnitTest++.h"
#include <Windows.h>
#include "MQPlugin.hpp"
#include "MQ3DMath.hpp"


TEST (MQ3DMath_dot)
{
	MQPoint v0 (1,0,0);
	MQPoint v1 (0,1,0);
	MQPoint v2 (0,0,1);

	CHECK_CLOSE (0, dot(v0, v1), 0.0001f);
	CHECK_CLOSE (0, dot(v1, v2), 0.0001f);
	CHECK_CLOSE (0, dot(v2, v0), 0.0001f);
	CHECK_CLOSE (1, dot(v0, v0), 0.0001f);
	CHECK_CLOSE (1, dot(v1, v1), 0.0001f);
	CHECK_CLOSE (1, dot(v2, v2), 0.0001f);
}

TEST (MQ3DMath_cross)
{
	MQPoint v0 (1,0,0);
	MQPoint v1 (0,1,0);
	MQPoint v2 (0,0,1);

	CHECK_CLOSE (0, cross(v0, v1).x, 0.0001f);
	CHECK_CLOSE (0, cross(v0, v1).y, 0.0001f);
	CHECK_CLOSE (1, cross(v0, v1).z, 0.0001f);
	CHECK_CLOSE (1, cross(v1, v2).x, 0.0001f);
	CHECK_CLOSE (0, cross(v1, v2).y, 0.0001f);
	CHECK_CLOSE (0, cross(v1, v2).z, 0.0001f);
	CHECK_CLOSE (0, cross(v2, v0).x, 0.0001f);
	CHECK_CLOSE (1, cross(v2, v0).y, 0.0001f);
	CHECK_CLOSE (0, cross(v2, v0).z, 0.0001f);

}

TEST (MQ3DMath_transpose)
{
	float m[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
	transpose (m);

	CHECK_EQUAL ( 0.f, m[0]);
	CHECK_EQUAL ( 4.f, m[1]);
	CHECK_EQUAL ( 8.f, m[2]);
	CHECK_EQUAL (12.f, m[3]);
	CHECK_EQUAL ( 1.f, m[4]);
	CHECK_EQUAL ( 5.f, m[5]);
	CHECK_EQUAL ( 9.f, m[6]);
	CHECK_EQUAL (13.f, m[7]);
	CHECK_EQUAL ( 2.f, m[8]);
	CHECK_EQUAL ( 6.f, m[9]);
	CHECK_EQUAL (10.f, m[10]);
	CHECK_EQUAL (14.f, m[11]);
	CHECK_EQUAL ( 3.f, m[12]);
	CHECK_EQUAL ( 7.f, m[13]);
	CHECK_EQUAL (11.f, m[14]);
	CHECK_EQUAL (15.f, m[15]);
}

TEST (MQ3DMath_invert)
{
	float m[16] = {1,2,0,0, 1,1,1,2, 1,2,1,2, 2,2,2,3};
	invert (m);

	CHECK_EQUAL ( 1.f, m[0]);
	CHECK_EQUAL ( 2.f, m[1]);
	CHECK_EQUAL (-2.f, m[2]);
	CHECK_EQUAL ( 0.f, m[3]);
	CHECK_EQUAL ( 0.f, m[4]);
	CHECK_EQUAL (-1.f, m[5]);
	CHECK_EQUAL ( 1.f, m[6]);
	CHECK_EQUAL ( 0.f, m[7]);
	CHECK_EQUAL (-1.f, m[8]);
	CHECK_EQUAL (-4.f, m[9]);
	CHECK_EQUAL ( 1.f, m[10]);
	CHECK_EQUAL ( 2.f, m[11]);
	CHECK_EQUAL ( 0.f, m[12]);
	CHECK_EQUAL ( 2.f, m[13]);
	CHECK_EQUAL ( 0.f, m[14]);
	CHECK_EQUAL (-1.f, m[15]);

}